package net.lzzy.practicesapi1.web.models;
import lombok.Getter;
import lombok.Setter;
import net.lzzy.practicesapi1.entities.Chapter;
import net.lzzy.practicesapi1.entities.Course;

import java.util.Date;
import java.util.UUID;
/**
 * @author lyz
 */
@Getter
@Setter
    public class VmCourse {
        private UUID id;
        private String Name;
        private String cover;
        private String desc;
        private Date createTime;
        private Date updateTime;
        private boolean open;
        private UUID teacherId;
        private String teacherName;
        private String teacherAvatar;
        private int countStudents;
        private int countChapters;

        private VmCourse(){}

        public static VmCourse create(Course course,boolean teacher){
            VmCourse vm = new VmCourse();
            vm.setId(course.getId());
            vm.setName(course.getName());
            vm.setCover(course.getCover());
            vm.setDesc(course.getDescription());
            vm.setOpen(course.isOpen());
            vm.setCreateTime(course.getCreateTime());
            vm.setUpdateTime((course.getUpdateTime()));
            vm.setTeacherName(course.getTeacher().getNickName());
            vm.setTeacherAvatar(course.getTeacher().getAvatar());
            vm.setCountStudents(course.getStudents().size());
            if (teacher){
                vm.setTeacherId(course.getTeacher().getId());
                vm.setCountStudents(course.getChapters().size());
            }else{
                vm.setCountChapters((int)course.getChapters().stream().filter(Chapter::isOpen).count());
            }return vm;
        }
    }


